package com.sibco.client.common.mail;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("unchecked")
public class MailBean {
	private String mailTo;
	private String[] recipientCCs;
	private String subject;
	private String content;
	private String templateType;
	private Map subjectParamMap = new HashMap();
	private Map contentParamMap = new HashMap();
	private MailService mailService;
	private String[][] files;
	
	public String[][] getFiles() {
		return files;
	}

	public void setFiles(String[][] files) {
		this.files = files;
	}

	public void setMailService(MailService mailService) {
		this.mailService = mailService;
	}
	
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getMailTo() {
		return mailTo;
	}
	public void setMailTo(String mailTo) {
		this.mailTo = mailTo;
	}
	public String[] getRecipientCCs() {
		return recipientCCs;
	}
	public void setRecipientCCs(String[] recipientCCs) {
		this.recipientCCs = recipientCCs;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public void addContentParam(String name,String value){
		contentParamMap.put(name,value);
	}
	public void addSubjectParam(String name,String value){
		subjectParamMap.put(name,value);
	}
	public String getTemplateType() {
		return templateType;
	}
	public void setTemplateType(String templateType) {
		this.templateType = templateType;
	}
	public Map getContentParamMap() {
		return contentParamMap;
	}
	public void setContentParamMap(Map contentParamMap) {
		this.contentParamMap = contentParamMap;
	}
	public Map getSubjectParamMap() {
		return subjectParamMap;
	}
	public void setSubjectParamMap(Map subjectParamMap) {
		this.subjectParamMap = subjectParamMap;
	}	
	
	public String getRealContent(){
		try{
			MailTemplate template = (MailTemplate) mailService.templateMap.get(this
					.getTemplateType());
			
			String content = template.getContent();
			Map param = this.getContentParamMap();
			content = mailService.getConvertedString(content, param);
			return content;
		}catch(Exception e){
			e.printStackTrace();			
			return null;
		}
		
	}

	public String getRealSubject( ){
		try{

			MailTemplate template = (MailTemplate) mailService.templateMap.get(this
					.getTemplateType());
		
			String subject = template.getSubject();
	
			Map param = this.getSubjectParamMap();
			subject = mailService.getConvertedString(subject, param);	
			return subject;
		}catch(Exception e){
			e.printStackTrace();			
			return null;
		}
	}
}
